import request from "@/utils/request";
import { AllTradeMark, HasSaleAttrResponseData, HasSpuResponseData, SaleAttrResponseData, skuData, skuInfoData, SpuHasImg } from "./type";

// SPU管理模块接口

enum API {
  // 获取已有的SPU数据接口
  HASSPU_URL = "/admin/product/",

  // 获取全部品牌的数据
  ALLTRADEMARK_URL = "/admin/product/baseTrademark/getTrademarkList",

  // 获取某一SPU下售卖商品图片数据
  IMAGE_URL = "/admin/product/spuImageList/",

  // 获取某一个SPU下全部的已有的销售属性接口地址
  SPUHASSALEATTR_URL = "/admin/product/spuSaleAttrList/",

  //获取整个项目全部的销售属性
  ALLSALEATTR_URL = "/admin/product/baseSaleAttrList",

  //更改SPU信息
  UPDATESPU_URL = '/admin/product/updateSpuInfo',

  // 添加SPU
  ADDSPU_URL = '/admin/product/saveSpuInfo',

  // 追加一个新增的SKU地址
  ADDSKU_URL = "/admin/product/saveSkuInfo",

  // 查看某一个已有的SPU下的全部售卖商品
  SKUINFO_URL = "/admin/product/findBySpuId/",

  // 删除已有的SPU
  REMOVESPU_URL = "/admin/product/deleteSpu/"
}

// 获取某一个三级分类下已有SPU数据接口方法
export const reqHasSpu = (page: number, limit: number, category3Id: number | string) => request.get<any, HasSpuResponseData>(API.HASSPU_URL + `${page}/${limit}?category3Id=${category3Id}`)

// 获取全部品牌的数据接口方法
export const reqAllTradeMark = () => request.get<any, AllTradeMark>(API.ALLTRADEMARK_URL)

// 获取某一SPU下售卖商品图片数据的接口方法
export const reqImageList = (spuId: number) => request.get<any, SpuHasImg>(API.IMAGE_URL + spuId)

// 获取某一个SPU下全部的已有的销售属性
export const reqSpuHasSaleAttr = (spuId: number) => request.get<any, SaleAttrResponseData>(API.SPUHASSALEATTR_URL + spuId)

// 获取全部的销售属性
export const reqAllSaleAttr = () => request.get<any, HasSaleAttrResponseData>(API.ALLSALEATTR_URL)

//添加或修改SPU接口
export const reqAddOrUpdateSpu = (data: any) => {
  if (data.id) {
    return request.post<any, any>(API.UPDATESPU_URL, data)
  } else {
    return request.post<any, any>(API.ADDSPU_URL, data)
  }
}

// 追加一个新增的SKU
export const reqAddSku = (data: skuData) => request.post<any, any>(API.ADDSKU_URL, data)

// 获取SKU数据
export const reqSkuList = (spuId: number | string) => request.get<any, skuInfoData>(API.SKUINFO_URL + spuId)

// 删除已有的SPU
export const reqRemoveSpu = (spuId:number|string)=>request.delete<any,any>(API.REMOVESPU_URL+spuId)